package org.bedracket.bedracketenchantment.enchantment;

import com.mojang.blaze3d.shaders.Effect;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;

public class TurnWeaponEnchantment extends Enchantment {
    public TurnWeaponEnchantment() {
        super(Rarity.RARE, EnchantmentCategory.WEAPON, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
    }

    @Override
    public int getMaxLevel() {
        return 5;
    }

    @Override
    public int getMinCost(int level) {
        return 1 + (level - 1) * 11;
    }

    @Override
    public void doPostAttack(LivingEntity pAttacker, Entity pTarget, int pLevel) {
        if (pTarget instanceof final LivingEntity living) {
            pAttacker.hurt(DamageSource.MAGIC, living.getActiveEffects().size());
            if (living.getActiveEffectsMap().containsKey(MobEffects.UNLUCK)) {
                living.hurt(DamageSource.MAGIC, living.getActiveEffects().size() * pLevel);
            }
        }
    }
}
